<?php
/**
 * Created by PhpStorm.
 * User: CYJiao
 * Date: 6/21/15
 * Time: 20:46
 */


class AtlasController extends Controller
{

    /**
     * Method returning filters array.
     */
    public function filters()
    {
        return array(
            'accessControl',//Performs access control for CRUD operations
        );
    }

    /**
     * Defines User Access Level.
     */
    public function accessRules()
    {
        return array(
            array('allow',
                'actions'=>array(),//Actions allowed
                'roles'=>array('@'),//Roles allowed to perform actions
            ),
            array('deny',
                'actions'=>array(),//Actions not allowed
                'roles'=>array('*'),//Roles not allowed to perform actions
            ),
        );
    }

    /**
     * Declares class-based actions.
     */
    public function actions(){
        return array(
            // captcha action renders the CAPTCHA image displayed on the contact page
            'captcha'=>array(
                'class'=>'CCaptchaAction',
                'height'=>37,
                'minLength'=>4,
                'maxLength'=>6,
                'backColor'=>0xFFFFFF,
            ),
            // page action renders "static" pages stored under 'protected/views/site/pages'
            // They can be accessed via: index.php?r=site/page&view=FileName
            'page'=>array(
                'class'=>'CViewAction',
            ),
        );
    }

    /**
     * Get ID from ID Server
     */
    private function getAutoID(){
        $id = curl_init();
        curl_setopt($id, CURLOPT_HEADER, 0);
        curl_setopt($id, CURLOPT_VERBOSE, 0);
        curl_setopt($id, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($id, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible;)");
        curl_setopt($id, CURLOPT_POST, true);
        curl_setopt($id, CURLOPT_URL, 'http://120.24.170.79:8080/push_call_server/get-id.do?accessToken=25da2c6fc3b8e5cfcd460b3367f7788e&logicid=8');
        $responseID = curl_exec($id);
        $result = json_decode($responseID,true);
        if($result['code']==0){
            return $result['content']['id'];
        }
    }

    /******************************************************************************************
     * Functions in Patient Atlas
     ******************************************************************************************/


    public function actionGetPatientAtlas($pk_outpatient_id){
        //Getting events active count,ticket sold from last login,new user registered after last login
        if(isset(Yii::app()->session['status']) && Yii::app()->session['status'] == 'logged') {
            $patientInformation = TblOutpatients::model()->findByAttributes(array('pk_outpatient_id'=>$pk_outpatient_id));
            $this->layout='main';
            $this->render('patientatlas',array('pk_outpatient_id'=>$pk_outpatient_id,'patientInformation'=>$patientInformation));
        }
        else
            $this->redirect(array('site/login'));//View redirection
    }

}

